﻿package view.popup
{
    import base.*;
    import com.core.*;
    import com.core.display.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.text.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import vo.*;

    public class ComDialogUI extends View implements IDialogUI
    {
        public var closeBtn:Button;
        public var icon:Image;
        public var checkBox:CheckBox;
        public var compoundBtn:Button;
        private var _tiptxt:TextField;
        private var oldtime:Number;
        private var _newid:int = 0;
        private var _type:int;
        protected var uiXML:XML;
        private var user_sex:int;
        private var userid:int;
        private var _gototype:int;

        public function ComDialogUI()
        {
            this.uiXML = <View>
n	t	t	t	t	t	t  <Image url=""png.common.cs2_tsbg"" x=""0"" y=""0"" sizeGrid=""10,50,10,50"" width=""344"" height=""258""/>
n	t	t	t	t	t	t  <Button skin=""png.common.btn_cs2_close"" x=""312"" y=""5"" var=""closeBtn""/>
n	t	t	t	t	t	t  <Image url=""png.common.img_2"" x=""139"" y=""90""/>
n	t	t	t	t	t	t  <Image url=""png.common.noramlicon"" x=""144"" y=""95"" var=""icon""/>
n	t	t	t	t	t	t  <CheckBox label=""取消合成提示"" skin=""png.common.checkbox_cs2_gx"" x=""122.5"" y=""186"" labelStroke=""0x0"" labelColors=""0xb29a6c,0xb29a6c,0xb29a6c"" var=""checkBox""/>
n	t	t	t	t	t	t  <Button label=""合成"" skin=""png.common.btn_cs2_bag"" x=""134"" y=""217"" labelColors=""0xb29a6c,0xb29a6c,0xb29a6c"" var=""compoundBtn"" labelStroke=""1"" labelFont=""SimSun""/>
n	t	t	t	t	t	t</View>")("<View>
						  <Image url="png.common.cs2_tsbg" x="0" y="0" sizeGrid="10,50,10,50" width="344" height="258"/>
						  <Button skin="png.common.btn_cs2_close" x="312" y="5" var="closeBtn"/>
						  <Image url="png.common.img_2" x="139" y="90"/>
						  <Image url="png.common.noramlicon" x="144" y="95" var="icon"/>
						  <CheckBox label="取消合成提示" skin="png.common.checkbox_cs2_gx" x="122.5" y="186" labelStroke="0x0" labelColors="0xb29a6c,0xb29a6c,0xb29a6c" var="checkBox"/>
						  <Button label="合成" skin="png.common.btn_cs2_bag" x="134" y="217" labelColors="0xb29a6c,0xb29a6c,0xb29a6c" var="compoundBtn" labelStroke="1" labelFont="SimSun"/>
						</View>;
            return;
        }// end function

        override protected function createChildren() : void
        {
            createView(this.uiXML);
            return;
        }// end function

        override protected function initialize() : void
        {
            super.initialize();
            this.userid = UserData.getUserData("career");
            var _loc_1:* = UserData.getUserData();
            this.user_sex = _loc_1.sex;
            (getChildAt(0) as Image).mouseChildren = true;
            this._tiptxt = Common.getTextField("", width, 20);
            this._tiptxt.defaultTextFormat = new TextFormat("宋体", 12, MColor.T_BLUE2, null, null, null, null, null, TextFormatAlign.CENTER);
            this._tiptxt.x = 0;
            this._tiptxt.y = 58;
            addChild(this._tiptxt);
            this._tiptxt.htmlText = "<font color=\'#ffffff\'>你身上有新的【</font>" + "速度快浪" + "<font color=\'#ffffff\'>】可以合成</font>";
            this.closeBtn.addEventListener(MouseEvent.CLICK, this.listenerHandler);
            this.compoundBtn.addEventListener(MouseEvent.CLICK, this.triggeredHandler);
            this.x = GlobalLayer.instance.root.stage.stageWidth - this.width >> 1;
            this.y = GlobalLayer.instance.root.stage.stageHeight - this.height >> 1;
            visible = false;
            return;
        }// end function

        private function listenerHandler(event:MouseEvent) : void
        {
            this.close();
            this.checkBox.selected = true;
            return;
        }// end function

        public function close() : void
        {
            visible = false;
            return;
        }// end function

        public function checkshow() : Boolean
        {
            var _loc_5:Object = null;
            var _loc_10:Object = null;
            var _loc_11:Object = null;
            var _loc_12:Object = null;
            var _loc_13:Number = NaN;
            var _loc_14:Object = null;
            if (this.checkBox && this.checkBox.selected)
            {
                return false;
            }
            if (getTimer() - this.oldtime < 4000)
            {
                return false;
            }
            if (PluginManager.instance.getPluginState("compound") == "open")
            {
                return false;
            }
            if (this.visible && this._newid > 0)
            {
                return false;
            }
            var _loc_1:* = UserData.getBagData();
            var _loc_2:* = ConfigDictionary.data.hechengmain;
            var _loc_3:* = _loc_1.maxcount;
            var _loc_4:* = new Object();
            var _loc_6:int = 1;
            while (_loc_6 <= _loc_3)
            {
                
                _loc_12 = _loc_1[_loc_6];
                if (_loc_12 && _loc_12[0] > 0)
                {
                    if (_loc_12[2] == 2)
                    {
                        if (_loc_2[_loc_12[0]])
                        {
                            _loc_13 = ModelProxy.getValue("data", "servertime") + Number(getTimer());
                            if (_loc_12[3] > 0 && _loc_12[3] < _loc_13 * 1000)
                            {
                            }
                            _loc_4[_loc_12[0]] = int(_loc_4[_loc_12[0]]) + _loc_12[1];
                        }
                    }
                    else
                    {
                        _loc_5 = _loc_12[4];
                        if (_loc_2[_loc_5.itemid])
                        {
                            _loc_4[_loc_5.itemid] = int(_loc_4[_loc_5.itemid]) + 1;
                        }
                    }
                }
                _loc_6++;
            }
            var _loc_7:* = UserData.getUserData();
            var _loc_8:* = ItemObject.create(_loc_7);
            ItemObject.create(_loc_7).arms = ModelProxy.getValue("data", "arms");
            var _loc_9:* = _loc_8.arms;
            for each (_loc_10 in _loc_9)
            {
                
                if (_loc_10 && _loc_5)
                {
                    if (_loc_10.itemid == int(_loc_5.itemid))
                    {
                        _loc_4[_loc_5.itemid] = int(_loc_4[_loc_5.itemid]) + 1;
                        break;
                    }
                }
            }
            for (_loc_11 in _loc_4)
            {
                
                _loc_14 = _loc_2[_loc_11];
                if (_loc_14)
                {
                    if (_loc_14.titltype == this.userid && _loc_14.sex == 2 || _loc_14.titltype == this.userid && _loc_14.sex == this.user_sex)
                    {
                        if (_loc_4[_loc_11] >= int(_loc_14.count) && _loc_14.assist == "")
                        {
                            this._type = _loc_14.newid;
                            return true;
                        }
                    }
                }
            }
            return false;
        }// end function

        public function show(param1:Object) : void
        {
            var _loc_4:String = null;
            if (!this.checkshow())
            {
                return;
            }
            if (this._type == 0)
            {
                this._type = 1;
            }
            visible = true;
            if (this._newid == this._type)
            {
                return;
            }
            this._newid = int(this._type);
            var _loc_2:* = ConfigDictionary.data.item;
            var _loc_3:* = _loc_2[this._newid];
            if (_loc_3 == null)
            {
                return;
            }
            this._tiptxt.htmlText = "<font color=\'#ffffff\'>你身上有新的【</font>" + _loc_3.name + "<font color=\'#ffffff\'>】可以合成</font>";
            _loc_4 = UIGlobel.getItemd(1);
            var _loc_5:* = _loc_4 + _loc_3.icon + Config.IconExtension;
            this.icon.url = _loc_5;
            this._type = 0;
            return;
        }// end function

        private function triggeredHandler(event:MouseEvent) : void
        {
            var _loc_6:Object = null;
            var _loc_7:int = 0;
            var _loc_2:* = UIGlobel.pointsDic["qianghua"];
            var _loc_3:* = GlobalLayer.instance.root.stage.stageWidth;
            var _loc_4:* = int((_loc_3 - 700) / 2);
            var _loc_5:* = ConfigDictionary.data.hechengnew;
            for each (_loc_6 in _loc_5)
            {
                
                if (_loc_6.newid == this._newid)
                {
                    this._gototype = _loc_6.itemtype;
                }
            }
            if (this._gototype == 1)
            {
                _loc_7 = 4;
            }
            if (this._gototype == 2)
            {
                _loc_7 = 3;
            }
            ModelProxy.change("plugin", "open", {target:"qianghua", point:new Point(_loc_2.x, _loc_2.y), top:new Point(_loc_4, 150), data:{gototype:_loc_7, newid:this._newid}});
            this.close();
            this.oldtime = getTimer();
            return;
        }// end function

    }
}
